package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShopCartMapper {
    /**
     * 获取当前用户购物车列表
     *
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> getCurrentUserShopCart(ShoppingCart shoppingCart);

    /**
     * 更新购物车
     *
     * @param cart
     */
    @Update("update shopping_cart set number = number+1 where user_id=#{userId};")
    void updateCartNumber(ShoppingCart cart);

    /**
     * 添加购物车
     *
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart(id, name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time)" +
            "values(null, #{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{number}, #{amount}, #{createTime})")
    void addCart(ShoppingCart shoppingCart);

    /**
     * 删除购物车
     *
     * @param currentId
     */
    @Delete("delete from shopping_cart where user_id = #{currentId}")
    void cleanCart(Long currentId);

    /**
     * 扣减购物车数量
     *
     * @param shoppingCart
     */
    void subCartNumber(ShoppingCart shoppingCart);

    /**
     * 获取当前用户购物车信息
     *
     * @param currentId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{currentId} and number=0")
    List<ShoppingCart> getCurrentUserShopCartInformation(Long currentId);

    /**
     *
     * @param cartIds
     */
    void deleteByIds(@Param("cartIds") List<Long> cartIds);

    /**
     * 批量插入购物车
     * @param shoppingCart
     */
    void insertBatch(@Param("shoppingCart") List<ShoppingCart> shoppingCart);
}
